package com.winit.common.schedule;

import com.winit.common.manager.CommonManager;
import com.winit.common.util.SpringContextHolder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * Created by wangjian on 17/1/4.
 */
@Component
public class BeetleScheduler {

    private static Logger logger = LoggerFactory.getLogger(BeetleScheduler.class);

    @Scheduled(cron = "0 0 0 * * ?")
    public void cleanEditionRelease() {
        logger.info("com.winit.common.schedule.BeetleScheduler.cleanEditionRelease");
        try {
            CommonManager commonManager = SpringContextHolder.getBean(CommonManager.class);
            commonManager.cleanReleaseDir();
        } catch (Exception e) {
            logger.error("com.winit.common.schedule.BeetleScheduler.cleanEditionRelease", e);
        }
    }

    @Scheduled(cron = "0 0 10 * * ?")
    public void cleanProject() {
        logger.info("com.winit.common.schedule.BeetleScheduler.cleanProject");
        try {
            CommonManager commonManager = SpringContextHolder.getBean(CommonManager.class);
            commonManager.cleanProject("beetle-schedule");
        } catch (Exception e) {
            logger.error("com.winit.common.schedule.BeetleScheduler.cleanProject", e);
        }
    }
}
